package com.hd123.rumba.gwt.widget.client.grid;

import com.hd123.rumba.gwt.widget.client.DateBox;

public class DateEditor extends DateBox implements CellEditor {

  public DateEditor() {
    super();
    super.setStyleName("DxGrid-CellEditor");
  }

  public void activate(DxGrid grid, int row, int col, String text, String width, String height,
      boolean readOnly) {
    super.setDateText(text);
    super.setWidth("100%");
    super.setHeight("97%");
    grid.setWidget(row, col, this);
    setReadOnly(readOnly);
    super.focus();
    super.getInputField().selectAll();
    if (text == null || text.length() == 0) {
      super.getInputField().setCursorPos(0);
    } else {
      super.getInputField().selectAll();
    }

  }

  public String getValue() {
    return this.getDateText();
  }

  public boolean isLeftKeyToLeave() {
    return getInputField().getCursorPos() == 0;
  }

  public boolean isRightKeyToLeave() {
    return getDateText() == null || getInputField().getCursorPos() == getDateText().trim().length();
  }

  public void setFocus(boolean focused) {
    this.getInputField().setFocus(focused);
  }

  public void setValue(String value) {
    setDateText(value);
  }

}
